from typing import Dict
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import uvicorn

# app.py

app = FastAPI(title="Simple FastAPI App")   

class Item(BaseModel):
    name: str
    description: str | None = None
    price: float
    available: bool = True

# In-memory "database"
items: Dict[int, Item] = {
    1: Item(name="Item 1", description="Description for Item 1", price=9.99),
    2: Item(name="Item 2", description="Description for Item 2", price=19.99),
    3: Item(name="Item 3", description="Description for Item 3", price=29.99)
}
_next_id = 1

@app.get("/")
async def read_root():
    return {"message": "Welcome to the simple FastAPI app"}

@app.get("/items")
async def list_items():
    return {"items": [{**item.dict(), "id": id} for id, item in items.items()]}

@app.get("/items/{item_id}")
async def get_item(item_id: int):
    item = items.get(item_id)
    if not item:
        raise HTTPException(status_code=404, detail="Item not found")
    return {"id": item_id, **item.dict()}

@app.post("/items", status_code=201)
async def create_item(item: Item):
    global _next_id
    item_id = _next_id
    items[item_id] = item
    _next_id += 1
    return {"id": item_id, **item.dict()}

@app.put("/items/{item_id}")
async def update_item(item_id: int, updated: Item):
    if item_id not in items:
        raise HTTPException(status_code=404, detail="Item not found")
    items[item_id] = updated
    return {"id": item_id, **updated.dict()}

@app.delete("/items/{item_id}", status_code=204)
async def delete_item(item_id: int):
    if item_id not in items:
        raise HTTPException(status_code=404, detail="Item not found")
    del items[item_id]
    return None

if __name__ == "__main__":
    uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)

def get_name_with_age(name: str, age: int):
    name_with_age = name + " is this old: " + str(age)
    return name_with_age